package com.metaverse.backend.security;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.metaverse.backend.enums.AuthorityName;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Objects;

@Entity
@Data
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer"}, ignoreUnknown = true)
public class Authority implements Serializable {

    public static Authority get(AuthorityName name) {
        return new Authority(name.name(), name.getDescription());
    }

    @Id
    @Size(max = 50)
    @NotNull
    @Column(length = 50)
    private String name;

    @Column(length = 50)
    @Size(max = 50)
    @NotNull
    private String description;

    /**
     * 是否隐藏
     */
    private boolean hide;


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Authority authority = (Authority) o;

        return Objects.equals(name, authority.name);
    }

    public Authority(){

    }

    public Authority(String name, String description){
        this.name = name;
        this.description = description;
    }

}
